package map.oj;

import java.util.*;

public class Num690 {
    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    public int getImportance(List<Employee> employees, int id) {
        Map<Integer,Employee> map = new HashMap<Integer,Employee>();
        for (Employee employee : employees){
            map.put(employee.id,employee);
        }
        int index = 0;
        Queue<Integer> queue = new LinkedList<Integer>();
        queue.offer(id);
        while (!queue.isEmpty()){
            int curId = queue.poll();
            Employee employee = map.get(curId);
            index += employee.importance;
            List<Integer> subordinates = employee.subordinates;
            for (int subId : subordinates){
                queue.offer(subId);
            }
        }
        return index;
    }
}
